﻿using UserService.Model;
using UserService.Repositorys;
using UserService.Services.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace UserService.Services
{
    [Dependency(ServiceLifetime.Transient)]
    public class UserService : CrudAppService<User, UserDto, Guid>, IUserService
    {
        private IUserRepository repository;
        public UserService(IUserRepository userRepository) : base(userRepository)
        {
            repository = userRepository;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<UserDto> UpdateAsync(Guid id, UserDto input)
        {
            var data = await repository.GetAsync(id);
            ObjectMapper.Map(input, data);
            User user = await repository.UpdateAsync(data);
            return ObjectMapper.Map<User, UserDto>(user);
        }
    }
}
